package cc.forgemod.customicon.client.renderer.inject;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.VarInsnNode;

import cc.forgemod.customicon.asm.ASMHelper;
import cc.forgemod.customicon.asm.loc.MethodDeter;
import cc.forgemod.customicon.asm.loc.MethodLoc;
import cc.forgemod.customicon.asm.op.OperatInsert;
import cc.forgemod.customicon.asm.op.OperatInsert.Direct;
import cc.forgemod.customicon.asm.op.OperateInterrupt;
import cc.forgemod.customicon.asm.op.OperateReplace;
import cc.forgemod.customicon.asm.transformer.ARenderTransformer;

public class RenderTransformer extends ARenderTransformer {

    public RenderTransformer() {
        super();

        this.mInjects.put("net.minecraft.client.gui.inventory.GuiContainer", (pData) -> transform(pData,
                new OperateInterrupt(MethodDeter.c("handleMouseClick", "func_184098_a", "a", "(Lagr;IILafw;)V")),
                new OperateReplace(MethodDeter.c("drawScreen", "func_148128_a", "a", "(IIF)V"),
                        MethodLoc.c("isMouseOverSlot", "func_146981_a", "a", "(Lagr;II)Z"))));

        this.mInjects.put("net.minecraft.client.multiplayer.PlayerControllerMP", (pData) -> transform(pData,
                // 禁止拿起,服务器有点击事件,无冲突
                new OperateReplace(MethodDeter.c("windowClick", "func_187098_a", "a", "(IIILafw;Laed;)Laip;"),
                        MethodLoc.c("slotClick", "func_184996_a", "a", "(IILafw;Laed;)Laip;"))));

        this.mInjects.put("net.minecraft.client.Minecraft", (pData) -> transform(pData,
                new OperatInsert(MethodDeter.c("displayGuiScreen", "func_147108_a", "a", "(Lblk;)V"))));

        this.mInjects.put("net.minecraft.client.renderer.ItemModelMesher", (pData) -> transform(pData,
                new OperatInsert(MethodDeter.c("getItemModel", "func_178089_a", "a", "(Laip;)Lcfy;"), Direct.AFTER_LOC,
                        new VarInsnNode(Opcodes.ALOAD, 1),
                        ASMHelper.createListenerCall("postGetItemModel"))
                                .setInsertLoc(MethodLoc.c("getItemModel", "func_178088_b", "b", "(Lain;I)Lcfy;"))));

    }

}
